import request from "@/utils/request";
import { AxiosPromise } from "axios";

import {
  ProductPageQuery,
  ProductPageResult,
  ProductSaveOrUpdateVO,
} from "./types";

/**
 * 分页列表
 *
 * @param queryParams
 */
export function getProductPage(
  queryParams: ProductPageQuery
): AxiosPromise<ProductPageResult> {
  return request({
    url: "/api/product/list",
    method: "get",
    params: queryParams,
  });
}

/**
 * 修改状态
 */
export function updateStatus(id: number, status: number) {
  return request({
    url: `/api/product/upOrDown/${id}/${status}`,
    method: "put",
  });
}

/**
 * 删除
 * @param id
 */
export function deleteProduct(id: number) {
  return request({
    url: `/api/product/delete/${id}`,
    method: "delete",
  });
}

/**
 * 新增
 * @param data
 */
export function addProduct(data: ProductSaveOrUpdateVO) {
  return request({
    url: "/api/product/add",
    method: "post",
    data,
  });
}

/**
 * 修改
 * @param data
 */
export function updateProduct(data: ProductSaveOrUpdateVO) {
  return request({
    url: "/api/product/update",
    method: "put",
    data,
  });
}

/**
 * 详情
 * @param id
 */
export function getProductDetail(id: number) {
  return request({
    url: `/api/product/${id}`,
    method: "get",
  });
}

/**
 * 批量删除
 */
export function batchDelete(ids: number[]) {
  return request({
    url: "/api/product/batch/delete",
    method: "delete",
    data: ids,
  });
}
